package com.rdzn.mall.center.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.rdzn.mall.center.entity.UmsFootprint;
import com.rdzn.mall.center.mapper.UmsFootprintMapper;
import com.rdzn.mall.center.service.IUmsFootprintService;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.Date;
import java.util.List;

/**
 * @Description: ums_footprint
 * @Author: jeecg-boot
 * @Date:   2020-10-13
 * @Version: V1.0
 */
@Service
public class UmsFootprintServiceImpl extends ServiceImpl<UmsFootprintMapper, UmsFootprint> implements IUmsFootprintService {

    @Override
    public UmsFootprint addFoot(Integer memberId, Integer productId) {
        UmsFootprint footprint = getOne(new LambdaQueryWrapper<UmsFootprint>().eq(UmsFootprint::getUserId, memberId).eq(UmsFootprint::getProductId, productId));
        if (footprint == null){
            footprint = new UmsFootprint();
            footprint.setCreateTime(new Date());
            footprint.setUpdateTime(new Date());
            footprint.setProductId(productId);
            footprint.setUserId(memberId);
            super.save(footprint);
        }else {
            footprint.setUpdateTime(new Date());
            super.updateById(footprint);
        }
        return footprint;
    }

    @Override
    public List<UmsFootprint> listByUserId(Integer memberId) {
        return list(new LambdaQueryWrapper<UmsFootprint>().eq(UmsFootprint::getUserId, memberId));
    }

    @Override
    public int countByUserId(Integer memberId) {
        return count(new LambdaQueryWrapper<UmsFootprint>().eq(UmsFootprint::getUserId, memberId));
    }
}
